﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GSPatEditor.Simulator
{
    class ActorActions
    {
        public static void ClearLabel(Actor actor)
        {
            actor.UpdateLabel = null;
            actor.SitLabel = null;
            actor.FallLabel = null;
            actor.EndMotionLabel = null;
            actor.EndKeyFrameLabel = null;
            actor.HitEvent = null;

            actor.Variables.Clear();
        }

        public static void ChangeFreeMove(Actor actor)
        {
            //TODO freeCancel
            //TODO warikomi
            ClearLabel(actor);
        }

        public static void BeginSit(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.Stand);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void BeginJump(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.Jump);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void BeginJumpForward(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.JumpForward);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void BeginWalk(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.Walk);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void BeginFall(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.Fall);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void BeginFallAttack(Actor actor)
        {
            var action = actor.Actions.GetSystemAction(Pat.SystemActionType.FallAttack);
            if (action == null)
            {
                actor.Release();
                return;
            }
            action.BeginAction(actor);
        }

        public static void PlayerEndToFreeMove(Actor actor)
        {
            ChangeFreeMove(actor);
            if (actor.IsInAir)
            {
                BeginFall(actor);
            }
            else
            {
                BeginSit(actor);
            }
        }
    }
}
